The CombinedErrorMessages control lets you combine error messages from several Validators
using one ErrorFormatter. It has several uses:
- When you are using an ErrorFormatter with an image, like
,
and there are several Validators that may appear simultaneously, you will see several
images, back-to-back. That looks strange. The CombinedErrorMessages control will
show just one image and display all of the relevant error messages.
- When you want to show all error messages in one place, add the CombinedErrorMessages
control where you want to show the error. The idea is similar to a ValidationSummary
control except it appears as fields are changed and its formatting matches other
Validators.
To use this control, add the normal validators but don't bother setting up their
ErrorFormatter,
NoErrorFormatter,
ErrorFormatterSkinID,
HiliteFields, or
ShowRequiredFieldMarker properties.
All appear on the CombinedErrorMessages control.
Add the CombinedErrorMessages control where the validator errors should appear.
Add PeterBlum.DES.Web.WebControls.ValidatorControlConnection objects to the
CombinedErrorMessages.Validators
property. Each ValidatorControlConnection's ControlID or
ControlInstance property points to a validator control.
Use the CombinedErrorFormatter's ErrorFormatter to establish
formatting of the error messages. It works the same as it does on
Validators.
Multiple error messages can be separated by line breaks (“list style”) or text (“paragraph style”).
Use the ListStyle property to select the format and the
ListLeadText and ParagraphSeparator properties to customize the formatting.
To have two validators report errors simultaneously, enter "abcdef" into the textbox.
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
if (PeterBlum.DES.Globals.WebFormDirector.IsValid)
{
}
}
</script>
To have two validators report errors simultaneously, enter "abcdef" into the textbox.<br/>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<des:CombinedErrorMessages ID="CombinedErrorMessages1" runat="server"
ShowRequiredFieldMarker="True">
<Validators>
<des:ValidatorControlConnection ControlID="Requiredtextvalidator1" />
<des:ValidatorControlConnection ControlID="TextLengthValidator1" />
<des:ValidatorControlConnection ControlID="RegexValidator1" />
</Validators>
<ErrorFormatterContainer>
<des:AlertImageErrorFormatter Display="Dynamic" />
</ErrorFormatterContainer>
</des:CombinedErrorMessages>
<des:RequiredTextValidator ID="RequiredTextValidator1" runat="server" ControlIDToEvaluate="TextBox1"
ErrorMessage="Required" SummaryErrorMessage="This textbox is required.">
</des:RequiredTextValidator>
<des:TextLengthValidator ID="TextLengthValidator1" runat="server" ControlIDToEvaluate="TextBox1"
ErrorMessage="Enter no more than {MAXIMUM} characters."
SummaryErrorMessage="Enter no more than {MAXIMUM} characters into the textbox" Maximum="5" >
</des:TextLengthValidator>
<des:RegexValidator ID="RegexValidator1" runat="server" ControlIDToEvaluate="TextBox1"
ErrorMessage="Enter only digits."
SummaryErrorMessage="Enter only digits into the textbox" Expression="^\d*$" />
<br/><br/>
<des:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click"></des:Button>
<input type="reset" value="Reset" id="Reset" runat="server" /><br/>
<des:ValidationSummary ID="ValidationSummary1" runat="server"
HeaderText="Fix these errors" />